package com.freesky.biz.icbc.controller;

import com.freesky.biz.icbc.domain.TAigouActivity;
import com.freesky.biz.icbc.domain.TMarketingActivity;
import com.freesky.biz.icbc.service.IAigouActivityService;
import com.freesky.biz.icbc.service.IMarketingActivityService;
import com.freesky.biz.utils.SeqUtil;
import com.freesky.common.annotation.Log;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工行爱购活动
 */
@RestController
@RequestMapping("/icbc/aigou/activity")
public class AiguoActivityController extends BaseController {

    @Autowired
    private IAigouActivityService aigouActivityService;

    @PreAuthorize("@ss.hasPermi('icbc:aigouactivity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAigouActivity entity) {
        startPage();
        List<TAigouActivity> list = aigouActivityService.selectAigouActivityList(entity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('icbc:aigouactivity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable String activityId) {
        return success(aigouActivityService.selectAigouActivityById(activityId));
    }

    @PreAuthorize("@ss.hasPermi('icbc:aigouactivity:add')")
    @Log(title = "工行爱购活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TAigouActivity entity) {
        entity.setCreateBy(String.valueOf(getUserId()));
        entity.setId(SeqUtil.getSeqId());
        return toAjax(aigouActivityService.insertAigouActivity(entity));
    }

    @PreAuthorize("@ss.hasPermi('icbc:aigouactivity:edit')")
    @Log(title = "工行爱购活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TAigouActivity entity) {
        entity.setUpdateBy(String.valueOf(getUserId()));
        return toAjax(aigouActivityService.updateAigouActivity(entity));
    }

    @PreAuthorize("@ss.hasPermi('icbc:aigouactivity:remove')")
    @Log(title = "工行爱购活动", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable String[] activityIds) {
        return toAjax(aigouActivityService.deleteAigouActivityByIds(activityIds));
    }

}
